﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

using System.Threading;
using System.Globalization;

using System.Collections;
using CE.Database;
using CE.Configuration;
/// <summary>
/// Summary description for General
/// admin@ - gg2012@CXT
/// broker1@ + broker2@ - more#SALES2012
/// </summary>
/// 
namespace CE.Global
{
    public class General
    {
        public static string UserId = "UserId";

        public static string UserProfileAndContactComplete = "IsProfileContactComplete";
        public static string UserGender = "UserGender";
        public static string UserTypeId = "UserTypeId";
        public static string SMTPAccountName = "SMTPAccountName";
        public static string SMTPAuthCode = "SMTPAuthCode";
        public static string SMTPReplyTo = "SMTPReplyTo";

        public static string UserCampaign = "UserCampaign";
        public static string UserRole = "UserRole";
        public static string IsRenewalAgent = "IsRenewalAgent";
        public static string IsMerchantAgent = "IsMerchantAgent";
        public static string IsCTPL = "IsCTPL";
        public static string UserEmail = "UserEmail";
        public static string UserPhoneNo = "UserPhone";
        public static string UserPhoneNoEN = "UserPhoneEN";
        public static string UserName = "UserName";
        public static string UserNameEN = "UserNameEN";
        public static string UserICNumber = "UserICNumber";
        public static string RequestUrl = "RequestUrl";
        public static string StartTime = "StartTime";
        public static string CallPageStartDateTime = "CallPageStartDateTime";
        public static string BuyNowCarID = "BuyNowCarID";
        public static string Guest = "Guest";
        public static string LoginHistoryId = "LoginHistoryId";
        public static string LastLoginTime = "LastLoginTime";
        public static string SecurityCheckWord = "Salt";

        public static string CarResultId = "CarResultId";
       

        ////Provider Session
        public static string ProviderCompanyId = "ProviderCompanyId";
        


        //View Details ID
        public static string ViewedDetailsId = "ViwedDetailsId";

        //DownLoad Proposal
        public static string RefId = "RefId";
        public static string InsType = "InsType";
        public static string InsParam = "InsParam";
        //Feed Back Receiver
        public General()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static DataTable GetComboItem(string keyName, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " Where [Status] = 1 ";
                    _sqlstatement += _sqlwhere;
                }

                _sqlstatement += " Order By " + _keyValueList[1];
                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
            }

            return _dt;
        }
        
        public static DataTable GetComboItem(string keyName, string OrderBy, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " Where [Status] = 1 ";
                    _sqlstatement += _sqlwhere;
                }

                if (OrderBy != "")
                {
                    _sqlstatement += " Order by " + OrderBy;
                }

                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }

            return _dt;
        }
        
        public static DataTable GetComboItem(string keyName, string whereKey, string whereId, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                _sqlstatement += " WHERE " + whereKey + " = " + whereId;
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " AND [Status] = 1;";
                    _sqlstatement += _sqlwhere;
                }

                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
            }

            return _dt;
        }

        

        public static Hashtable GetDayList(int sMonth, int sYear)
        {
            int _daycount = 31;
            bool isLeapYear = DateTime.IsLeapYear(sYear);

            if (isLeapYear && sMonth == 2)
            {
                _daycount = 29;
            }
            else if (sMonth == 2)
            {
                _daycount = 28;
            }
            else if (sMonth == 4 || sMonth == 6 || sMonth == 9 || sMonth == 11)
            {
                _daycount = 30;
            }
            else
            {
                _daycount = 31;
            }
            Hashtable ht_day = new Hashtable(_daycount);
            for (int i = _daycount; i >= 1; i--)
            {
                ht_day.Add(i, i);
            }

            return ht_day;
        }

        public static Hashtable GetDOBYearList()
        {
            int _sYear = Convert.ToInt32(MyConfigurationManager.GetAppSettingValue("StartDOBYear"));
            int _eYear = Convert.ToInt32(MyConfigurationManager.GetAppSettingValue("EndDOBYear"));
            int _yCount = _eYear - _sYear;
            Hashtable ht_year = new Hashtable(_yCount);

            for (int i = _sYear; i <= _eYear; i++)
            {
                ht_year.Add(i, i);
            }

            return ht_year;
        }

        public static Hashtable GetMonthList(string format)
        {
            Hashtable ht_month = new Hashtable(12);
            DateTime dt = new DateTime(2009, 1, 1);
            for (int i = 1; i <= 12; i++)
            {
                string monthName = string.Format("{0:" + format + "}", dt.AddMonths(i - 1));
                ht_month.Add(i, monthName);
            }
            return ht_month;
        }

        public static string ClearScriptTag(string strSource)
        {
            String sourcestring = strSource;
            String matchpattern = @"<script[^>]*?.*?</script>";
            //String matchpattern = @"<script\s[^>]*?</script>";
            //String matchpattern = @"<script\s[^>]*>(?:(?!</script>).)*?\r\n(?:function blabla\(\)|blabla\(\);)(?:(?!</script>).)*?</script>";
            String replacementpattern = @"";
            String result = Regex.Replace(sourcestring, matchpattern, replacementpattern, RegexOptions.IgnoreCase);
            return result;
        }

        public static bool IsInteger(String strNumber)
        {
            Regex objNotNaturalPattern = new Regex("[^0-9]");
            Regex objNaturalPattern = new Regex("[0-9][0-9]*");

            return !objNotNaturalPattern.IsMatch(strNumber) &&
            objNaturalPattern.IsMatch(strNumber);
        }

        public static string GetRefNumber(string strExceptType, string PostedDate, string ID)
        {
            String _result = "";
            String _refnumber = "";
            MyDatabase _db = new MyDatabase();
            String _strSql = "SELECT CONVERT(VARCHAR,(CONVERT(DATETIME,'" + PostedDate + "',103)),112)";
            _result = _db.ExecuteScalarSqlStatement(_strSql).ToString();
            _refnumber = strExceptType + _result + ID;
            return _refnumber;
        }

        public static string GetRefNumber(Int64 FirstId)
        {
            string _vallasttwo = "";
            string _valfirstchar = "";
            string _valsecondchar = "";
            string _valremaining = "";
            string _result = "";
            Int64 _firstId = FirstId;
            if (_firstId.ToString().Length >= 2)
            {
                _valremaining = _firstId.ToString().Substring(0, _firstId.ToString().Length - 2);
                _vallasttwo = _firstId.ToString().Substring(_firstId.ToString().Length - 2, 2);
                _valfirstchar = _vallasttwo.Substring(0, 1);
                _valsecondchar = _vallasttwo.Substring(1, 1);
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _valsecondchar = NumberToChar(Convert.ToInt32(_valsecondchar));
                _result = _valremaining + "" + _valfirstchar + "" + _valsecondchar;
            }
            else if (_firstId.ToString().Length == 1)
            {
                _valfirstchar = _firstId.ToString();
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _result = _valfirstchar;
            }
          
            return _result;
        }

        public static string NumberToChar(int id)
        {
            string C = "";
            if (id == 1)
                C = "A";
            else if (id == 2)
                C = "B";
            else if (id == 3)
                C = "C";
            else if (id == 4)
                C = "D";
            else if (id == 5)
                C = "E";
            else if (id == 6)
                C = "F";
            else if (id == 7)
                C = "G";
            else if (id == 8)
                C = "H";
            else if (id == 9)
                C = "I";
            else if (id == 0)
                C = "J";
            return C;
        }

        public static string GetCarId(string QuoteNo)
        {
            string _val = "";
            string _result = "0";
            string str = QuoteNo;
            char[] letters = str.ToCharArray();
            if (QuoteNo.Substring(0, 2) == "GG")
            {
                for (int i = 4; i < letters.Length; i++)
                {
                    _val += StringToNumber(letters[i].ToString());
                }
            }
            else if (QuoteNo.Substring(0, 2) == "FL")
            {
                for (int i = 5; i < letters.Length; i++)
                {
                    _val += StringToNumber(letters[i].ToString());
                }
            }
            else if (QuoteNo.Substring(0, 1) == "M" && QuoteNo.Substring(0, 3) != "MTI"
                && QuoteNo.Substring(0, 3) != "MSI" && QuoteNo.Substring(0, 3) != "MIR")
            {
                for (int i = (letters.Length - 5); i < letters.Length; i++)
                {
                    _val += StringToNumber(letters[i].ToString());
                }
            }
            else
            {
                for (int i = 3; i < letters.Length; i++)
                {
                    _val += StringToNumber(letters[i].ToString());
                }
            }
            if (_val.Length > 0 && IsInteger(_val) == true)
            {
                _result = _val;
            }
            return _result;
        }

        public static string StringToNumber(string No)
        {
            string C = "";
            if (No.ToUpper() == "A")
                C = "1";
            else if (No.ToUpper() == "B")
                C = "2";
            else if (No.ToUpper() == "C")
                C = "3";
            else if (No.ToUpper() == "D")
                C = "4";
            else if (No.ToUpper() == "E")
                C = "5";
            else if (No.ToUpper() == "F")
                C = "6";
            else if (No.ToUpper() == "G")
                C = "7";
            else if (No.ToUpper() == "H")
                C = "8";
            else if (No.ToUpper() == "I")
                C = "9";
            else if (No.ToUpper() == "J")
                C = "0";
            else
                C = No;
            return C;
        }

        public static void ClearAllSession(System.Web.UI.Page PageSession, string strExceptType)
        {
            if (strExceptType == "LOGOUT")
            {
                ClearUserLoginCached(PageSession);
                PageSession.Session["UserId"] = null;
                PageSession.Session["UserTypeId"] = null;
                PageSession.Session["UserEmail"] = null;
                PageSession.Session["UserPhoneNo"] = null;
                PageSession.Session["UserName"] = null;
                PageSession.Session["UserCampaign"] = null;
                PageSession.Session["UserRole"] = null;

                PageSession.Session["UserICNumber"] = null;
                PageSession.Session["RequestUrl"] = null;
                PageSession.Session["StartTime"] = null;
                //PageSession.Session["Guest"] = null;
                PageSession.Session["LoginHistoryId"] = null;
                PageSession.Session["LastLoginTime"] = null;
                PageSession.Session["ProviderCompanyId"] = null;
            }
        }

        public static void CreateUpdateUserLoginCached(System.Web.UI.Page thisPage)
        {
            string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXCRMUserCacheName");
            sKey += Convert.ToString(thisPage.Session[UserId].ToString());
            // Accessing the Cache Item extends the Sliding Expiration automatically
            if (thisPage.Cache[sKey] != null)
            {
                string sUser = thisPage.Cache[sKey].ToString();
            }
            else
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, thisPage.Session.Timeout, 0, 0);
                thisPage.Cache.Insert(sKey, thisPage.Session[UserId].ToString(), null, DateTime.MaxValue, SessTimeOut,
                   System.Web.Caching.CacheItemPriority.NotRemovable, null);
            }
        }

        public static bool ClearUserLoginCached(System.Web.UI.Page thisPage)
        {
            bool _retValue = false;
            string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXCRMUserCacheName");
            sKey += thisPage.Session[UserId].ToString();

            if (thisPage.Cache[sKey] == null)
            {
                _retValue = true;
            }
            else
            {
                thisPage.Cache.Remove(sKey);
                _retValue = true;
            }

            return _retValue;
        }

        public static String SetCulture()
        {
            String selectedCulture = string.Empty;
            if (System.Web.HttpContext.Current.Session["Language"] != null)
            {
                selectedCulture = System.Web.HttpContext.Current.Session["Language"].ToString();
            }
            else
            {
                //selectedCulture = "th-TH";
                selectedCulture = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig("system.web/globalization"))).UICulture;
                System.Web.HttpContext.Current.Session["Language"] = selectedCulture;
            }

            //UICulture = selectedCulture;
            //Culture = selectedCulture;

            //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedCulture);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedCulture);

            return selectedCulture;
        }

        /*Sakthi on 10 Jul 2012 -- Start */

        public static string GetReferenceNumber(string Number, string ProviderId)
        {
            string convertno = CE.Global.General.GetRefNumber(Convert.ToInt64(Number.ToString()));
            string _RefNo = "";
            if (ProviderId == "11")
            {
                _RefNo = "AZC" + convertno.ToString();
            }
            else if (ProviderId == "12")
            {
                _RefNo = "MSI" + convertno.ToString();
            }
            else if (ProviderId == "16")
            {
                _RefNo = "AXA" + convertno.ToString();
            }
            else if (ProviderId == "29")
            {
                _RefNo = "LMG" + convertno.ToString();
            }
            else if (ProviderId == "31")
            {
                _RefNo = "CTS" + convertno.ToString();
            }
            else if (ProviderId == "32")
            {
                _RefNo = "BKI" + convertno.ToString();
            }
            else if (ProviderId == "33")
            {
                _RefNo = "MTI" + convertno.ToString();
            }
            else if (ProviderId == "35")
            {
                _RefNo = "KPI" + convertno.ToString();
            }
            else if (ProviderId == "39")
            {
                _RefNo = "MIR" + convertno.ToString();
            }
            else if (ProviderId == "41")
            {
                //_RefNo = "KUR" + convertno.ToString();
                _RefNo = "KSK" + convertno.ToString();
            }
            else if (ProviderId == "43")
            {
                _RefNo = "SMK" + convertno.ToString();
            }
            else if (ProviderId == "45")
            {
                _RefNo = "VRY" + convertno.ToString();
            }
            else if (ProviderId == "46")
            {
                _RefNo = "TMS" + convertno.ToString();
            }
            else if (ProviderId == "50")
            {
                _RefNo = "SCS" + convertno.ToString();
            }
            else if (ProviderId == "58")
            {
                _RefNo = "TVV" + convertno.ToString();
            }
            else if (ProviderId == "65")
            {
                _RefNo = "DPY" + convertno.ToString();
            }
            else if (ProviderId == "51")
            {
                _RefNo = "SMG" + convertno.ToString();
            }
            else if (ProviderId == "66")
            {
                _RefNo = "TPB" + convertno.ToString();
            }
            else if (ProviderId == "67")
            {
                _RefNo = "DVS" + convertno.ToString();
            }
            else if (ProviderId == "68")
            {
                _RefNo = "THI" + convertno.ToString();
            }
            else if (ProviderId == "69")
            {
                _RefNo = "ASE" + convertno.ToString();
            }
            return _RefNo;
        }

        public static string GetGGReferenceNumber(string Number, string ProviderId)
        {
            string convertno = CE.Global.General.GetRefNumber(Convert.ToInt64(Number.ToString()));
            string _RefNo = "GG" + ProviderId.ToString() + convertno.ToString();            
            return _RefNo;
        }

        public static string GetFleetReferenceNumber(string Number, string ProviderId)
        {
            string convertno = CE.Global.General.GetFLRefNumber(Convert.ToInt64(Number.ToString()));
            //string _RefNo = "FL" + ProviderId.ToString() + convertno.ToString();
            string _RefNo = "FL";
            if (ProviderId == "11")
            {
                _RefNo += "AZC" + convertno.ToString();
            }
            else if (ProviderId == "12")
            {
                _RefNo += "MSI" + convertno.ToString();
            }
            else if (ProviderId == "16")
            {
                _RefNo += "AXA" + convertno.ToString();
            }
            else if (ProviderId == "29")
            {
                _RefNo += "LMG" + convertno.ToString();
            }
            else if (ProviderId == "31")
            {
                _RefNo += "CTS" + convertno.ToString();
            }
            else if (ProviderId == "32")
            {
                _RefNo += "BKI" + convertno.ToString();
            }
            else if (ProviderId == "33")
            {
                _RefNo += "MTI" + convertno.ToString();
            }
            else if (ProviderId == "35")
            {
                _RefNo += "KPI" + convertno.ToString();
            }
            else if (ProviderId == "39")
            {
                _RefNo += "MIR" + convertno.ToString();
            }
            else if (ProviderId == "41")
            {
                _RefNo += "KSK" + convertno.ToString();
            }
            else if (ProviderId == "43")
            {
                _RefNo += "SMK" + convertno.ToString();
            }
            else if (ProviderId == "45")
            {
                _RefNo += "VRY" + convertno.ToString();
            }
            else if (ProviderId == "46")
            {
                _RefNo += "TMS" + convertno.ToString();
            }
            else if (ProviderId == "50")
            {
                _RefNo += "SCS" + convertno.ToString();
            }
            else if (ProviderId == "58")
            {
                _RefNo += "TVV" + convertno.ToString();
            }
            else if (ProviderId == "65")
            {
                _RefNo += "DPY" + convertno.ToString();
            }
            else if (ProviderId == "51")
            {
                _RefNo += "SMG" + convertno.ToString();
            }
            else if (ProviderId == "66")
            {
                _RefNo += "TPB" + convertno.ToString();
            }
            else if (ProviderId == "67")
            {
                _RefNo += "DVS" + convertno.ToString();
            }
            else if (ProviderId == "68")
            {
                _RefNo += "THI" + convertno.ToString();
            }
            else if (ProviderId == "69")
            {
                _RefNo += "ASE" + convertno.ToString();
            }
            return _RefNo;
        }

        public static string GetFLRefNumber(Int64 FirstId)
        {
            string _vallasttwo = "";
            string _valfirstchar = "";
            string _valsecondchar = "";
            string _valremaining = "";
            string _result = "";
            string _firstId = FirstId.ToString();
            if (_firstId.ToString().Length >= 2)
            {
                _valremaining = _firstId.ToString().Substring(0, _firstId.ToString().Length - 2);
                _vallasttwo = _firstId.ToString().Substring(_firstId.ToString().Length - 2, 2);
                _valfirstchar = _vallasttwo.Substring(0, 1);
                _valsecondchar = _vallasttwo.Substring(1, 1);
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _valsecondchar = NumberToChar(Convert.ToInt32(_valsecondchar));
                _result = _valremaining + "" + _valfirstchar + "" + _valsecondchar;
            }
            else if (_firstId.ToString().Length == 1)
            {
                _valfirstchar = _firstId.ToString();
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _result = _valfirstchar;
            }

            return _result;
        }

        public static string GetMerchantReferenceNumber(string Number, string ProviderId, string MerchantId)
        {
            string convertno = CE.Global.General.GetMCRefNumber(Convert.ToInt64(Number.ToString()));
            //string _RefNo = "MC" + ProviderId.ToString() + convertno.ToString();
            string _RefNo = "M" + MerchantId.PadLeft(3, '0') + ProviderId + convertno;
            return _RefNo;
        }

        public static string GetMCRefNumber(Int64 FirstId)
        {
            string _vallasttwo = "";
            string _valfirstchar = "";
            string _valsecondchar = "";
            string _valremaining = "";
            string _result = "";
            string _firstId = FirstId.ToString();
            if (_firstId.ToString().Length >= 2)
            {
                _valremaining = _firstId.ToString().Substring(0, _firstId.ToString().Length - 2);
                _vallasttwo = _firstId.ToString().Substring(_firstId.ToString().Length - 2, 2);
                _valfirstchar = _vallasttwo.Substring(0, 1);
                _valsecondchar = _vallasttwo.Substring(1, 1);
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _valsecondchar = NumberToChar(Convert.ToInt32(_valsecondchar));
                _result = _valremaining + "" + _valfirstchar + "" + _valsecondchar;
            }
            else if (_firstId.ToString().Length == 1)
            {
                _valfirstchar = _firstId.ToString();
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _result = _valfirstchar;
            }

            return _result;
        }

        public static string GetProviderName(Int64 ProviderCompanyId)
        {
            string _result = "";
            if (ProviderCompanyId == 11)
            {
                _result = "อลิอันซ์ ซี.พี. ประกันภัย";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "เอ็ม เอส ไอ จี ประกันภัย";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "แอกซ่า ประกันภัย";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "แอลเอ็มจี ประกันภัย";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "กรุงเทพประกันภัย";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "เมืองไทยประกันภัย";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "กรุงไทยพานิชประกันภัย";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "มิตรแท้ประกันภัย";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "เค เอส เค";// "คูเนีย ประกันภัย";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "สินมั่นคงประกันภัย";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "วิริยะประกันภัย";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "โตเกียวมารีนศรีเมือง";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "ไทยพาณิชย์สามัคคีประกันภัย";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "ประกันภัยไทยวิวัฒน์";
            }
            else if (ProviderCompanyId == 65)
            {
                _result = "ทิพยประกันภัย";
            }
            else if (ProviderCompanyId == 51)
            {
                _result = "สามัคคีประกันภัย";
            }
            else if (ProviderCompanyId == 66)
            {
                _result = "ไทยไพบูลย์";
            }
            else if (ProviderCompanyId == 67)
            {
                _result = "เทเวศประกันภัย";
            }
            else if (ProviderCompanyId == 68)
            {
                _result = "ไทยศรีประกันภัย";
            }
            else if (ProviderCompanyId == 69)
            {
                _result = "สินทรัพย์ประกันภัย";
            }
            return _result;
        }

        public static string GetProviderName(Int64 ProviderCompanyId, string Language)
        {
            string _result = "";
            if (Language == "1")
            {
                if (ProviderCompanyId == 11)
                {
                    _result = "อลิอันซ์ ซี.พี. ประกันภัย";
                }
                else if (ProviderCompanyId == 12)
                {
                    _result = "เอ็ม เอส ไอ จี ประกันภัย";
                }
                else if (ProviderCompanyId == 16)
                {
                    _result = "แอกซ่า ประกันภัย";
                }
                else if (ProviderCompanyId == 29)
                {
                    _result = "แอลเอ็มจี ประกันภัย";
                }
                else if (ProviderCompanyId == 31)
                {
                    _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
                }
                else if (ProviderCompanyId == 32)
                {
                    _result = "กรุงเทพประกันภัย";
                }
                else if (ProviderCompanyId == 33)
                {
                    _result = "เมืองไทยประกันภัย";
                }
                else if (ProviderCompanyId == 35)
                {
                    _result = "กรุงไทยพานิชประกันภัย";
                }
                else if (ProviderCompanyId == 39)
                {
                    _result = "มิตรแท้ประกันภัย";
                }
                else if (ProviderCompanyId == 41)
                {
                    _result = "เค เอส เค";// "คูเนีย ประกันภัย";
                }
                else if (ProviderCompanyId == 43)
                {
                    _result = "สินมั่นคงประกันภัย";
                }
                else if (ProviderCompanyId == 45)
                {
                    _result = "วิริยะประกันภัย";
                }
                else if (ProviderCompanyId == 46)
                {
                    _result = "โตเกียวมารีนศรีเมือง";
                }
                else if (ProviderCompanyId == 50)
                {
                    _result = "ไทยพาณิชย์สามัคคีประกันภัย";
                }
                else if (ProviderCompanyId == 58)
                {
                    _result = "ประกันภัยไทยวิวัฒน์";
                }
                else if (ProviderCompanyId == 65)
                {
                    _result = "ทิพยประกันภัย";
                }
                else if (ProviderCompanyId == 51)
                {
                    _result = "สามัคคีประกันภัย";
                }
                else if (ProviderCompanyId == 66)
                {
                    _result = "ไทยไพบูลย์";
                }
                else if (ProviderCompanyId == 67)
                {
                    _result = "เทเวศประกันภัย";
                }
                else if (ProviderCompanyId == 68)
                {
                    _result = "ไทยศรีประกันภัย";
                }
                else if (ProviderCompanyId == 69)
                {
                    _result = "สินทรัพย์ประกันภัย";
                }
            }
            else if (Language == "2")
            {
                if (ProviderCompanyId == 11)
                {
                    _result = "Allianz CP Insurance";
                }
                else if (ProviderCompanyId == 12)
                {
                    _result = "MSIG Insurance";
                }
                else if (ProviderCompanyId == 16)
                {
                    _result = "AXA Insurance";
                }
                else if (ProviderCompanyId == 29)
                {
                    _result = "LMG  Insurance";
                }
                else if (ProviderCompanyId == 31)
                {
                    _result = "Chartis Insurance";
                }
                else if (ProviderCompanyId == 32)
                {
                    _result = "BKI Insurance";
                }
                else if (ProviderCompanyId == 33)
                {
                    _result = "MuangThai Insurance";
                }
                else if (ProviderCompanyId == 35)
                {
                    _result = "KrungThai Insurance";
                }
                else if (ProviderCompanyId == 39)
                {
                    _result = "Mittare Insurance";
                }
                else if (ProviderCompanyId == 41)
                {
                    _result = "KSK Insurance";
                }
                else if (ProviderCompanyId == 43)
                {
                    _result = "Synmunkong Insurance";
                }
                else if (ProviderCompanyId == 45)
                {
                    _result = "Viriyah Insurance";
                }
                else if (ProviderCompanyId == 46)
                {
                    _result = "Tokio Marine Insurance";
                }
                else if (ProviderCompanyId == 50)
                {
                    _result = "SCSMG Insurance";
                }
                else if (ProviderCompanyId == 58)
                {
                    _result = "Thaivivat Insurance";
                }
                else if (ProviderCompanyId == 65)
                {
                    _result = "Dhipaya Insurance";
                }
                else if (ProviderCompanyId == 66)
                {
                    _result = "Thaipaiboon Insurance";
                }
                else if (ProviderCompanyId == 67)
                {
                    _result = "Deves Insurance";
                }
                else if (ProviderCompanyId == 68)
                {
                    _result = "ThaiSri Insurance";
                }
                else if (ProviderCompanyId == 69)
                {
                    _result = "Assets Insurance";
                }
            }
            return _result;
        }

        public static string GetProviderBrokerCode(Int64 ProviderCompanyId)
        {
            string _result = "";
            if (ProviderCompanyId == 11)
            {
                _result = "001600";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "AFM1012";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "BB115";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "BR00619";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "002851000";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "641100";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "74000352";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "-/207";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "PP96834";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "198700-00";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "2130-000";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "11261";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "10233002";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "300191";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "002113-1";
            }
            else if (ProviderCompanyId == 65)
            {
                _result = "BKBR120065";
            }
            else if (ProviderCompanyId == 51)
            {
                _result = "300191";
            }
            else if (ProviderCompanyId == 66)
            {
                _result = "10813481";
            }
            else if (ProviderCompanyId == 67)
            {
                _result = "90003140 Source 807881";
            }
            else if (ProviderCompanyId == 68)
            {
                _result = "4534";
            }
            else if (ProviderCompanyId == 69)
            {
                _result = "1200531";
            }
            return _result;
        }

        public static string GetProviderMail(Int64 ProviderCompanyId)
        {
            string _result = "";
            if (ProviderCompanyId == 11)
            {
                _result = "TO_AZCP";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "TO_MSIG";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "TO_AXA";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "TO_LMG";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "TO_CTS";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "TO_BKI";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "TO_MTI";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "TO_KPI";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "TO_MIR";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "TO_KUR";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "TO_SMK";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "TO_VRY";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "TO_TMS";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "TO_SCS";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "TO_TVV";
            }
            else if (ProviderCompanyId == 65)
            {
                _result = "TO_DPY";
            }
            else if (ProviderCompanyId == 51)
            {
                _result = "TO_SCS";
            }
            else if (ProviderCompanyId == 66)
            {
                _result = "TO_TPB";
            }
            else if (ProviderCompanyId == 67)
            {
                _result = "TO_DVS";
            }
            else if (ProviderCompanyId == 68)
            {
                _result = "TO_THI";
            }
            else if (ProviderCompanyId == 69)
            {
                _result = "TO_ASE";
            }
            return _result;
        }

        public static string GetProvider(Int64 ProviderCompanyId)
        {
            string _result = "";
            if (ProviderCompanyId == 11)
            {
                _result = "AZCP";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "MSIG";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "AXA";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "LMG";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "CTS";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "BKI";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "MTI";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "KPI";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "MIR";
            }
            else if (ProviderCompanyId == 41)
            {
                //_result = "KUR";
                _result = "KSK";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "SMK";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "VRY";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "TMS";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "SCS";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "TVV";
            }
            else if (ProviderCompanyId == 65)
            {
                _result = "DPY";
            }
            else if (ProviderCompanyId == 51)
            {
                _result = "SMG";
            }
            else if (ProviderCompanyId == 66)
            {
                _result = "TPB";
            }
            else if (ProviderCompanyId == 67)
            {
                _result = "DVS";
            }
            else if (ProviderCompanyId == 68)
            {
                _result = "THI";
            }
            else if (ProviderCompanyId == 69)
            {
                _result = "ASE";
            }
            return _result;
        }

        public static string GetProviderId(string Provider)
        {
            string _result = Provider;
            if (Provider.ToUpper() == "AZC")
            {
                _result = "11";
            }
            else if (Provider.ToUpper() == "MSI")
            {
                _result = "12";
            }
            else if (Provider.ToUpper() == "AXA")
            {
                _result = "16";
            }
            else if (Provider.ToUpper() == "LMG")
            {
                _result = "29";
            }
            else if (Provider.ToUpper() == "CTS")
            {
                _result = "31";
            }
            else if (Provider.ToUpper() == "BKI")
            {
                _result = "32";
            }
            else if (Provider.ToUpper() == "MTI")
            {
                _result = "33";
            }
            else if (Provider.ToUpper() == "KPI")
            {
                _result = "35";
            }
            else if (Provider.ToUpper() == "MIR")
            {
                _result = "39";
            }
            else if (Provider.ToUpper() == "KUR" || Provider.ToUpper() == "KSK")
            {
                _result = "41";
            }
            else if (Provider.ToUpper() == "SMK")
            {
                _result = "43";
            }
            else if (Provider.ToUpper() == "VRY")
            {
                _result = "45";
            }
            else if (Provider.ToUpper() == "TMS")
            {
                _result = "46";
            }
            else if (Provider.ToUpper() == "SCS")
            {
                _result = "50";
            }
            else if (Provider.ToUpper() == "TVV")
            {
                _result = "58";
            }
            else if (Provider.ToUpper() == "DPY")
            {
                _result = "65";
            }
            else if (Provider.ToUpper() == "SMG")
            {
                _result = "51";
            }
            else if (Provider.ToUpper() == "TPB")
            {
                _result = "66";
            }
            else if (Provider.ToUpper() == "DVS")
            {
                _result = "67";
            }
            else if (Provider.ToUpper() == "THI")
            {
                _result = "68";
            }
            else if (Provider.ToUpper() == "ASE")
            {
                _result = "69";
            }
            return _result;
        }

        public static string GetProviderCompanyLogo(string providerid)
        {
            string logourl = "/images/ProviderCompanyLogo/";
            if (providerid == "11")
            {
                logourl += "allianz-cp.png";
            }
            else if (providerid == "12")
            {
                logourl += "msig.png";
            }
            else if (providerid == "16")
            {
                logourl += "axa.png";
            }
            else if (providerid == "29")
            {
                logourl += "lmg.png";
            }
            else if (providerid == "31")
            {
                logourl += "chartis.png";
            }
            else if (providerid == "32")
            {
                logourl += "bki.png";
            }
            else if (providerid == "33")
            {
                logourl += "muangthai.png";
            }
            else if (providerid == "35")
            {
                logourl += "krungthai.png";
            }
            else if (providerid == "39")
            {
                logourl += "mittare.png";
            }
            else if (providerid == "41")
            {
                logourl += "ksk.png";
            }
            else if (providerid == "43")
            {
                logourl += "synmunkong.png";
            }
            else if (providerid == "45")
            {
                logourl += "viriyah.png";
            }                
            else if (providerid == "46")
            {
                logourl += "tokiomarine.png";
            }
            else if (providerid == "50")
            {
                logourl += "scsmg.png";
            }
            else if (providerid == "58")
            {
                logourl += "thaivivat.png";
            }
            else if (providerid == "65")
            {
                logourl += "dhipaya.png";
            }
            else if (providerid == "51")
            {
                logourl += "smg.png";
            }
            else if (providerid == "66")
            {
                logourl += "thaipaiboon.png";
            }
            else if (providerid == "67")
            {
                logourl += "deves.png";
            }
            else if (providerid == "68")
            {
                logourl += "thaisri.png";
            }
            else if (providerid == "69")
            {
                logourl += "asset.png";
            }
            return logourl;
        }

        /*Sakthi on 10 Jul 2012 -- End */

        public static DateTime GetUTCDateTime()
        {
            DateTime _CurrentDateTime = DateTime.UtcNow.AddHours(7);
            return _CurrentDateTime;
        }

        public static DateTime GetUTCDateTimeToday()
        {
            DateTime _CurrentDateTime = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc);
            return _CurrentDateTime;
        }
    }

    public enum CEUserType
    {
        SiteAdmin = 100,
        SiteUser = 200,
        Provider = 300,
        Customer = 400,
        OffLineCustomer = 410,
        Advertiser = 500,
        Guest = 600,
        Management = 700
    }



}
